#include<bits/stdc++.h>
using namespace std;

bool check(int x)
{
	while(x)
	{
		if(x%10 == 7)
			return false;
		x /= 10;
	}
	return true;
}

int main()
{
	int n;
	int ans = 0;
	cin>>n;
	for(int i = 1;i <= n;i++)
	{
		if(i%7 != 0 && check(i))
			ans += i*i;
	}
	cout<<ans;
	return 0;
}

